package day12.homework1;

import java.util.regex.Pattern;

public class UserService {

    public void register(User user) throws AccountExistException, IllegalDataException {
        if("admin".equals(user.getUsername())) throw new AccountExistException();
        // \w包含 数字字母下划线美元符号
        Pattern pattern = Pattern.compile("^[a-zA-Z]\\w{4,9}$");
        if (!pattern.matcher(user.getUsername()).matches()) throw new IllegalDataException();
        if (!pattern.matcher(user.getPassword()).matches()) throw new IllegalDataException();
        // 可以去存数据库了
    }
}
